const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const optimizeCssAssetsWebpackPlugin = require("optimize-css-assets-webpack-plugin"); //压缩css
const UglifyWebpackPlugin = require("uglifyjs-webpack-plugin"); //压缩js
const commonConfig = require("./webpack.common.js");
const merge = require("webpack-merge");

let productConfig = {
  mode: "production",
  module: {
    rules: [
      {
        test: /\.css|.styl|.less$/,
        use: [
          { loader: MiniCssExtractPlugin.loader },
          { loader: "css-loader" },
          { loader: "stylus-loader" },
          {
            loader: "postcss-loader"
          }
        ]
      }
    ]
  },
  plugins: [
    new MiniCssExtractPlugin({
      // 类似 webpackOptions.output里面的配置 可以忽略
      filename: "[name].[hash].css",
      chunkFilename: "[id].[hash].css"
    })
  ],
  optimization: {
    minimizer: [
      new optimizeCssAssetsWebpackPlugin({}),
      new UglifyWebpackPlugin({
        cache: true,
        parallel: true,
        sourceMap: false
      })
    ]
  }
};

module.exports = merge(commonConfig, productConfig);
